home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / image_cont.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  106 lines

  1. ; $Id: image_cont.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. pro image_cont, a, WINDOW_SCALE = window_scale, ASPECT = aspect, $
  7.     INTERP = interp
  8. ;+
  9. ; NAME:
  10. ;    IMAGE_CONT
  11. ;
  12. ; PURPOSE:
  13. ;    Overlay an image and a contour plot.
  14. ;
  15. ; CATEGORY:
  16. ;    General graphics.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    IMAGE_CONT, A
  20. ;
  21. ; INPUTS:
  22. ;    A:    The two-dimensional array to display.
  23. ;
  24. ; KEYWORD PARAMETERS:
  25. ; WINDOW_SCALE:    Set this keyword to scale the window size to the image size.
  26. ;        Otherwise, the image size is scaled to the window size.
  27. ;        This keyword is ignored when outputting to devices with 
  28. ;        scalable pixels (e.g., PostScript).
  29. ;
  30. ;    ASPECT:    Set this keyword to retain the image's aspect ratio.
  31. ;        Square pixels are assumed.  If WINDOW_SCALE is set, the 
  32. ;        aspect ratio is automatically retained.
  33. ;
  34. ;    INTERP:    If this keyword is set, bilinear interpolation is used if 
  35. ;        the image is resized.
  36. ;
  37. ; OUTPUTS:
  38. ;    No explicit outputs.
  39. ;
  40. ; COMMON BLOCKS:
  41. ;    None.
  42. ;
  43. ; SIDE EFFECTS:
  44. ;    The currently selected display is affected.
  45. ;
  46. ; RESTRICTIONS:
  47. ;    None.
  48. ;
  49. ; PROCEDURE:
  50. ;    If the device has scalable pixels, then the image is written over
  51. ;    the plot window.
  52. ;
  53. ; MODIFICATION HISTORY:
  54. ;    DMS, May, 1988.
  55. ;-
  56.  
  57. on_error,2                      ;Return to caller if an error occurs
  58. sz = size(a)            ;Size of image
  59. if sz[0] lt 2 then message, 'Parameter not 2D'
  60.  
  61.     ;set window used by contour
  62. contour,[[0,0],[1,1]],/nodata, xstyle=4, ystyle = 4
  63.  
  64. px = !x.window * !d.x_vsize    ;Get size of window in device units
  65. py = !y.window * !d.y_vsize
  66. swx = px[1]-px[0]        ;Size in x in device units
  67. swy = py[1]-py[0]        ;Size in Y
  68. six = float(sz[1])        ;Image sizes
  69. siy = float(sz[2])
  70. aspi = six / siy        ;Image aspect ratio
  71. aspw = swx / swy        ;Window aspect ratio
  72. f = aspi / aspw            ;Ratio of aspect ratios
  73.  
  74. if (!d.flags and 1) ne 0 then begin    ;Scalable pixels?
  75.   if keyword_set(aspect) then begin    ;Retain aspect ratio?
  76.                 ;Adjust window size
  77.     if f ge 1.0 then swy = swy / f else swx = swx * f
  78.     endif
  79.  
  80.   tvscl,a,px[0],py[0],xsize = swx, ysize = swy, /device
  81.  
  82. endif else begin    ;Not scalable pixels    
  83.    if keyword_set(window_scale) then begin ;Scale window to image?
  84.     tvscl,a,px[0],py[0]    ;Output image
  85.     swx = six        ;Set window size from image
  86.     swy = siy
  87.     endif else begin        ;Scale window
  88.     if keyword_set(aspect) then begin
  89.         if f ge 1.0 then swy = swy / f else swx = swx * f
  90.         endif        ;aspect
  91.     tv,poly_2d(bytscl(a),$    ;Have to resample image
  92.         [[0,0],[six/swx,0]], [[0,siy/swy],[0,0]],$
  93.         keyword_set(interp),swx,swy), $
  94.         px[0],py[0]
  95.     endelse            ;window_scale
  96.   endelse            ;scalable pixels
  97.  
  98. mx = !d.n_colors-1        ;Brightest color
  99. colors = [mx,mx,mx,0,0,0]    ;color vectors
  100. if !d.name eq 'PS' then colors = mx - colors ;invert line colors for pstscrp
  101. contour,a,/noerase,/xst,/yst,$    ;Do the contour
  102.        pos = [px[0],py[0], px[0]+swx,py[0]+swy],/dev,$
  103.     c_color =  colors
  104. return
  105. end
  106.